import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('商品列表'),
      ),
      body: HYHomeContent(),
    );
  }
}

class HYHomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        HYHomeProductItem('Apple1', 'MacBook1',
            'http://n.sinaimg.cn/default/1_img/upload/3933d981/731/w930h601/20200905/93bb-iytwsca2096537.jpg'),
        SizedBox(height: 6,),
        HYHomeProductItem('Apple2', 'MacBook2',
            'http://n.sinaimg.cn/news/1_img/upload/c4b46437/750/w930h620/20200906/3047-iytwsca3281793.jpg'),
        SizedBox(height: 6,),
        HYHomeProductItem('Apple3', 'MacBook3',
            'http://n.sinaimg.cn/default/1_img/upload/3933d981/750/w930h620/20200905/9487-iytwsca2606087.jpg'),
      ],
    );
  }
}

class HYHomeProductItem extends StatelessWidget {
  final String title;
  final String desc;
  final String imageUrl;

  HYHomeProductItem(this.title, this.desc, this.imageUrl);

  final style1 = TextStyle(fontSize: 25, color: Colors.orange);
  final style2 = TextStyle(fontSize: 25, color: Colors.green);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(8),
      decoration: BoxDecoration(
        border: Border.all(
            width: 5,//设置边框宽度
            color: Colors.black45//设置边框颜色
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: style1,
          ),
          SizedBox(
            height: 8,
          ),
          Text(
            desc,
            style: style2,
          ),
          SizedBox(
            height: 8,
          ),
          Image.network(imageUrl),
        ],
      ),
    );
  }
}
